package com.exercises;


import com.exercises.common.ListNode;

class Exercise82 {
    public static void main(String[] args) {
        int[] a = new int[]{1, 1, 1, 2, 3, 4, 4};
        ListNode head = null, l = null;
        for (int i : a) {
            if (l == null) {
                head = l = new ListNode(i);
            } else {
                l.next = new ListNode(i);
                l = l.next;
            }
        }
//        while (head != null) {
//            System.out.println(head.val);
//            head = head.next;
//        }

        head = deleteDuplicates(head);
        while (head != null) {
            System.out.println(head.val);
            head = head.next;
        }
    }



    public static ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) return head;

        if (head.val == head.next.val) {
            while (head.val == head.next.val) {
                head = head.next;
                if (head.next == null) {
                    break;
                }
            }
            return deleteDuplicates(head.next);
        } else {
            head.next = deleteDuplicates(head.next);
            return head;
        }


    }

}

